#!/bin/bash
#description install codis
SOFTDIR=/usr/local/src
GOVER=1.9.4
#install go environment
yum -y install gcc glibc gcc-c++ make git
cd $SOFTDIR
[ ! -f go${GOVER}.linux-amd64.tar.gz ] && wget http://soft.51yuki.cn/go${GOVER}.linux-amd64.tar.gz
tar -C /usr/local -xzf go${GOVER}.linux-amd64.tar.gz
#add system evironment variable
#work is GOPATH dir
mkdir -p /usr/local/go/work
cat > /etc/profile.d/go.sh <<EOF
 export GOROOT=/usr/local/go
 export GOPATH=/usr/local/go/work
 export PATH=$PATH:$GOROOT/bin
EOF
source /etc/profile.d/go.sh

#download codis and install codis
mkdir -p $GOPATH/src/github.com/CodisLabs
cd $_ && git clone https://github.com/CodisLabs/codis.git -b release3.2.1
make
cd $GOPATH/src/github.com/CodisLabs/codis/
for ser in codis-dashboard-admin.sh codis-fe-admin.sh codis-proxy-admin.sh codis-server-admin.sh;do
	./admin/$ser start
done
if [ "`ss -tunlp|grep 9090|awk -F "[ :]+" '{print $5}'`" == "9090" -a "`ss -tunlp|grep 11080|awk -F "[ :]+" '{print $5}'`" == "11080" -a "`ss -tunlp|grep 19000|awk -F "[ :]+" '{print $5}'`" == "19000" -a "`ss -tunlp|grep 18080|awk -F "[ :]+" '{print $5}'`" == "18080"  -a "`ss -tunlp|grep 6379|awk -F "[ :]+" '{print $5}'`" == "6379"  ];then
	echo "codis start successful"
else
	echo "codis start fail"
fi
 


